home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacPerl 5.0.3 / MacPerl Source ƒ / Perl5 / ext / Socket / Socket.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-29  |  9.8 KB  |  606 lines  |  [TEXT/MPS ]

  1. #include "EXTERN.h"
  2. #include "perl.h"
  3. #include "XSUB.h"
  4.  
  5. #include <sys/socket.h>
  6.  
  7. #ifndef AF_NBS
  8. #undef PF_NBS
  9. #endif
  10.  
  11. #ifndef AF_X25
  12. #undef PF_X25
  13. #endif
  14.  
  15. static int
  16. not_here(s)
  17. char *s;
  18. {
  19.     croak("Socket::%s not implemented on this architecture", s);
  20.     return -1;
  21. }
  22.  
  23. static double
  24. constant(name, arg)
  25. char *name;
  26. int arg;
  27. {
  28.     errno = 0;
  29.     switch (*name) {
  30.     case 'A':
  31.     if (strEQ(name, "AF_802"))
  32. #ifdef AF_802
  33.         return AF_802;
  34. #else
  35.         goto not_there;
  36. #endif
  37.     if (strEQ(name, "AF_APPLETALK"))
  38. #ifdef AF_APPLETALK
  39.         return AF_APPLETALK;
  40. #else
  41.         goto not_there;
  42. #endif
  43.     if (strEQ(name, "AF_CCITT"))
  44. #ifdef AF_CCITT
  45.         return AF_CCITT;
  46. #else
  47.         goto not_there;
  48. #endif
  49.     if (strEQ(name, "AF_CHAOS"))
  50. #ifdef AF_CHAOS
  51.         return AF_CHAOS;
  52. #else
  53.         goto not_there;
  54. #endif
  55.     if (strEQ(name, "AF_DATAKIT"))
  56. #ifdef AF_DATAKIT
  57.         return AF_DATAKIT;
  58. #else
  59.         goto not_there;
  60. #endif
  61.     if (strEQ(name, "AF_DECnet"))
  62. #ifdef AF_DECnet
  63.         return AF_DECnet;
  64. #else
  65.         goto not_there;
  66. #endif
  67.     if (strEQ(name, "AF_DLI"))
  68. #ifdef AF_DLI
  69.         return AF_DLI;
  70. #else
  71.         goto not_there;
  72. #endif
  73.     if (strEQ(name, "AF_ECMA"))
  74. #ifdef AF_ECMA
  75.         return AF_ECMA;
  76. #else
  77.         goto not_there;
  78. #endif
  79.     if (strEQ(name, "AF_GOSIP"))
  80. #ifdef AF_GOSIP
  81.         return AF_GOSIP;
  82. #else
  83.         goto not_there;
  84. #endif
  85.     if (strEQ(name, "AF_HYLINK"))
  86. #ifdef AF_HYLINK
  87.         return AF_HYLINK;
  88. #else
  89.         goto not_there;
  90. #endif
  91.     if (strEQ(name, "AF_IMPLINK"))
  92. #ifdef AF_IMPLINK
  93.         return AF_IMPLINK;
  94. #else
  95.         goto not_there;
  96. #endif
  97.     if (strEQ(name, "AF_INET"))
  98. #ifdef AF_INET
  99.         return AF_INET;
  100. #else
  101.         goto not_there;
  102. #endif
  103.     if (strEQ(name, "AF_LAT"))
  104. #ifdef AF_LAT
  105.         return AF_LAT;
  106. #else
  107.         goto not_there;
  108. #endif
  109.     if (strEQ(name, "AF_MAX"))
  110. #ifdef AF_MAX
  111.         return AF_MAX;
  112. #else
  113.         goto not_there;
  114. #endif
  115.     if (strEQ(name, "AF_NBS"))
  116. #ifdef AF_NBS
  117.         return AF_NBS;
  118. #else
  119.         goto not_there;
  120. #endif
  121.     if (strEQ(name, "AF_NIT"))
  122. #ifdef AF_NIT
  123.         return AF_NIT;
  124. #else
  125.         goto not_there;
  126. #endif
  127.     if (strEQ(name, "AF_NS"))
  128. #ifdef AF_NS
  129.         return AF_NS;
  130. #else
  131.         goto not_there;
  132. #endif
  133.     if (strEQ(name, "AF_OSI"))
  134. #ifdef AF_OSI
  135.         return AF_OSI;
  136. #else
  137.         goto not_there;
  138. #endif
  139.     if (strEQ(name, "AF_OSINET"))
  140. #ifdef AF_OSINET
  141.         return AF_OSINET;
  142. #else
  143.         goto not_there;
  144. #endif
  145.     if (strEQ(name, "AF_PUP"))
  146. #ifdef AF_PUP
  147.         return AF_PUP;
  148. #else
  149.         goto not_there;
  150. #endif
  151.     if (strEQ(name, "AF_SNA"))
  152. #ifdef AF_SNA
  153.         return AF_SNA;
  154. #else
  155.         goto not_there;
  156. #endif
  157.     if (strEQ(name, "AF_UNIX"))
  158. #ifdef AF_UNIX
  159.         return AF_UNIX;
  160. #else
  161.         goto not_there;
  162. #endif
  163.     if (strEQ(name, "AF_UNSPEC"))
  164. #ifdef AF_UNSPEC
  165.         return AF_UNSPEC;
  166. #else
  167.         goto not_there;
  168. #endif
  169.     if (strEQ(name, "AF_X25"))
  170. #ifdef AF_X25
  171.         return AF_X25;
  172. #else
  173.         goto not_there;
  174. #endif
  175. #ifdef macintosh
  176.     if (strEQ(name, "AF_UNSPEC"))
  177.         return AF_UNSPEC;
  178.     if (strEQ(name, "AF_CTB"))
  179.         return AF_CTB;
  180.     if (strEQ(name, "AF_PPC"))
  181.         return AF_PPC;
  182.     if (strEQ(name, "AF_PAP"))
  183.         return AF_PAP;
  184. #endif
  185.     break;
  186.     case 'B':
  187.     break;
  188.     case 'C':
  189.     break;
  190.     case 'D':
  191.     break;
  192.     case 'E':
  193.     break;
  194.     case 'F':
  195.     break;
  196.     case 'G':
  197.     break;
  198.     case 'H':
  199.     break;
  200.     case 'I':
  201.     break;
  202.     case 'J':
  203.     break;
  204.     case 'K':
  205.     break;
  206.     case 'L':
  207.     break;
  208.     case 'M':
  209.     if (strEQ(name, "MSG_DONTROUTE"))
  210. #ifdef MSG_DONTROUTE
  211.         return MSG_DONTROUTE;
  212. #else
  213.         goto not_there;
  214. #endif
  215.     if (strEQ(name, "MSG_MAXIOVLEN"))
  216. #ifdef MSG_MAXIOVLEN
  217.         return MSG_MAXIOVLEN;
  218. #else
  219.         goto not_there;
  220. #endif
  221.     if (strEQ(name, "MSG_OOB"))
  222. #ifdef MSG_OOB
  223.         return MSG_OOB;
  224. #else
  225.         goto not_there;
  226. #endif
  227.     if (strEQ(name, "MSG_PEEK"))
  228. #ifdef MSG_PEEK
  229.         return MSG_PEEK;
  230. #else
  231.         goto not_there;
  232. #endif
  233.     break;
  234.     case 'N':
  235.     break;
  236.     case 'O':
  237.     break;
  238.     case 'P':
  239.     if (strEQ(name, "PF_802"))
  240. #ifdef PF_802
  241.         return PF_802;
  242. #else
  243.         goto not_there;
  244. #endif
  245.     if (strEQ(name, "PF_APPLETALK"))
  246. #ifdef PF_APPLETALK
  247.         return PF_APPLETALK;
  248. #else
  249.         goto not_there;
  250. #endif
  251.     if (strEQ(name, "PF_CCITT"))
  252. #ifdef PF_CCITT
  253.         return PF_CCITT;
  254. #else
  255.         goto not_there;
  256. #endif
  257.     if (strEQ(name, "PF_CHAOS"))
  258. #ifdef PF_CHAOS
  259.         return PF_CHAOS;
  260. #else
  261.         goto not_there;
  262. #endif
  263.     if (strEQ(name, "PF_DATAKIT"))
  264. #ifdef PF_DATAKIT
  265.         return PF_DATAKIT;
  266. #else
  267.         goto not_there;
  268. #endif
  269.     if (strEQ(name, "PF_DECnet"))
  270. #ifdef PF_DECnet
  271.         return PF_DECnet;
  272. #else
  273.         goto not_there;
  274. #endif
  275.     if (strEQ(name, "PF_DLI"))
  276. #ifdef PF_DLI
  277.         return PF_DLI;
  278. #else
  279.         goto not_there;
  280. #endif
  281.     if (strEQ(name, "PF_ECMA"))
  282. #ifdef PF_ECMA
  283.         return PF_ECMA;
  284. #else
  285.         goto not_there;
  286. #endif
  287.     if (strEQ(name, "PF_GOSIP"))
  288. #ifdef PF_GOSIP
  289.         return PF_GOSIP;
  290. #else
  291.         goto not_there;
  292. #endif
  293.     if (strEQ(name, "PF_HYLINK"))
  294. #ifdef PF_HYLINK
  295.         return PF_HYLINK;
  296. #else
  297.         goto not_there;
  298. #endif
  299.     if (strEQ(name, "PF_IMPLINK"))
  300. #ifdef PF_IMPLINK
  301.         return PF_IMPLINK;
  302. #else
  303.         goto not_there;
  304. #endif
  305.     if (strEQ(name, "PF_INET"))
  306. #ifdef PF_INET
  307.         return PF_INET;
  308. #else
  309.         goto not_there;
  310. #endif
  311.     if (strEQ(name, "PF_LAT"))
  312. #ifdef PF_LAT
  313.         return PF_LAT;
  314. #else
  315.         goto not_there;
  316. #endif
  317.     if (strEQ(name, "PF_MAX"))
  318. #ifdef PF_MAX
  319.         return PF_MAX;
  320. #else
  321.         goto not_there;
  322. #endif
  323.     if (strEQ(name, "PF_NBS"))
  324. #ifdef PF_NBS
  325.         return PF_NBS;
  326. #else
  327.         goto not_there;
  328. #endif
  329.     if (strEQ(name, "PF_NIT"))
  330. #ifdef PF_NIT
  331.         return PF_NIT;
  332. #else
  333.         goto not_there;
  334. #endif
  335.     if (strEQ(name, "PF_NS"))
  336. #ifdef PF_NS
  337.         return PF_NS;
  338. #else
  339.         goto not_there;
  340. #endif
  341.     if (strEQ(name, "PF_OSI"))
  342. #ifdef PF_OSI
  343.         return PF_OSI;
  344. #else
  345.         goto not_there;
  346. #endif
  347.     if (strEQ(name, "PF_OSINET"))
  348. #ifdef PF_OSINET
  349.         return PF_OSINET;
  350. #else
  351.         goto not_there;
  352. #endif
  353.     if (strEQ(name, "PF_PUP"))
  354. #ifdef PF_PUP
  355.         return PF_PUP;
  356. #else
  357.         goto not_there;
  358. #endif
  359.     if (strEQ(name, "PF_SNA"))
  360. #ifdef PF_SNA
  361.         return PF_SNA;
  362. #else
  363.         goto not_there;
  364. #endif
  365.     if (strEQ(name, "PF_UNIX"))
  366. #ifdef PF_UNIX
  367.         return PF_UNIX;
  368. #else
  369.         goto not_there;
  370. #endif
  371.     if (strEQ(name, "PF_UNSPEC"))
  372. #ifdef PF_UNSPEC
  373.         return PF_UNSPEC;
  374. #else
  375.         goto not_there;
  376. #endif
  377.     if (strEQ(name, "PF_X25"))
  378. #ifdef PF_X25
  379.         return PF_X25;
  380. #else
  381.         goto not_there;
  382. #endif
  383. #ifdef macintosh
  384.     if (strEQ(name, "PF_UNSPEC"))
  385.         return PF_UNSPEC;
  386.     if (strEQ(name, "PF_CTB"))
  387.         return PF_CTB;
  388.     if (strEQ(name, "PF_PPC"))
  389.         return PF_PPC;
  390.     if (strEQ(name, "PF_PAP"))
  391.         return PF_PAP;
  392. #endif
  393.     break;
  394.     case 'Q':
  395.     break;
  396.     case 'R':
  397.     break;
  398.     case 'S':
  399.     if (strEQ(name, "SOCK_DGRAM"))
  400. #ifdef SOCK_DGRAM
  401.         return SOCK_DGRAM;
  402. #else
  403.         goto not_there;
  404. #endif
  405.     if (strEQ(name, "SOCK_RAW"))
  406. #ifdef SOCK_RAW
  407.         return SOCK_RAW;
  408. #else
  409.         goto not_there;
  410. #endif
  411.     if (strEQ(name, "SOCK_RDM"))
  412. #ifdef SOCK_RDM
  413.         return SOCK_RDM;
  414. #else
  415.         goto not_there;
  416. #endif
  417.     if (strEQ(name, "SOCK_SEQPACKET"))
  418. #ifdef SOCK_SEQPACKET
  419.         return SOCK_SEQPACKET;
  420. #else
  421.         goto not_there;
  422. #endif
  423.     if (strEQ(name, "SOCK_STREAM"))
  424. #ifdef SOCK_STREAM
  425.         return SOCK_STREAM;
  426. #else
  427.         goto not_there;
  428. #endif
  429.     if (strEQ(name, "SOL_SOCKET"))
  430. #ifdef SOL_SOCKET
  431.         return SOL_SOCKET;
  432. #else
  433.         goto not_there;
  434. #endif
  435.     if (strEQ(name, "SOMAXCONN"))
  436. #ifdef SOMAXCONN
  437.         return SOMAXCONN;
  438. #else
  439.         goto not_there;
  440. #endif
  441.     if (strEQ(name, "SO_ACCEPTCONN"))
  442. #ifdef SO_ACCEPTCONN
  443.         return SO_ACCEPTCONN;
  444. #else
  445.         goto not_there;
  446. #endif
  447.     if (strEQ(name, "SO_BROADCAST"))
  448. #ifdef SO_BROADCAST
  449.         return SO_BROADCAST;
  450. #else
  451.         goto not_there;
  452. #endif
  453.     if (strEQ(name, "SO_DEBUG"))
  454. #ifdef SO_DEBUG
  455.         return SO_DEBUG;
  456. #else
  457.         goto not_there;
  458. #endif
  459.     if (strEQ(name, "SO_DONTLINGER"))
  460. #ifdef SO_DONTLINGER
  461.         return SO_DONTLINGER;
  462. #else
  463.         goto not_there;
  464. #endif
  465.     if (strEQ(name, "SO_DONTROUTE"))
  466. #ifdef SO_DONTROUTE
  467.         return SO_DONTROUTE;
  468. #else
  469.         goto not_there;
  470. #endif
  471.     if (strEQ(name, "SO_ERROR"))
  472. #ifdef SO_ERROR
  473.         return SO_ERROR;
  474. #else
  475.         goto not_there;
  476. #endif
  477.     if (strEQ(name, "SO_KEEPALIVE"))
  478. #ifdef SO_KEEPALIVE
  479.         return SO_KEEPALIVE;
  480. #else
  481.         goto not_there;
  482. #endif
  483.     if (strEQ(name, "SO_LINGER"))
  484. #ifdef SO_LINGER
  485.         return SO_LINGER;
  486. #else
  487.         goto not_there;
  488. #endif
  489.     if (strEQ(name, "SO_OOBINLINE"))
  490. #ifdef SO_OOBINLINE
  491.         return SO_OOBINLINE;
  492. #else
  493.         goto not_there;
  494. #endif
  495.     if (strEQ(name, "SO_RCVBUF"))
  496. #ifdef SO_RCVBUF
  497.         return SO_RCVBUF;
  498. #else
  499.         goto not_there;
  500. #endif
  501.     if (strEQ(name, "SO_RCVLOWAT"))
  502. #ifdef SO_RCVLOWAT
  503.         return SO_RCVLOWAT;
  504. #else
  505.         goto not_there;
  506. #endif
  507.     if (strEQ(name, "SO_RCVTIMEO"))
  508. #ifdef SO_RCVTIMEO
  509.         return SO_RCVTIMEO;
  510. #else
  511.         goto not_there;
  512. #endif
  513.     if (strEQ(name, "SO_REUSEADDR"))
  514. #ifdef SO_REUSEADDR
  515.         return SO_REUSEADDR;
  516. #else
  517.         goto not_there;
  518. #endif
  519.     if (strEQ(name, "SO_REUSEPORT"))
  520. #ifdef SO_REUSEPORT
  521.         return SO_REUSEPORT;
  522. #else
  523.         goto not_there;
  524. #endif
  525.     if (strEQ(name, "SO_SNDBUF"))
  526. #ifdef SO_SNDBUF
  527.         return SO_SNDBUF;
  528. #else
  529.         goto not_there;
  530. #endif
  531.     if (strEQ(name, "SO_SNDLOWAT"))
  532. #ifdef SO_SNDLOWAT
  533.         return SO_SNDLOWAT;
  534. #else
  535.         goto not_there;
  536. #endif
  537.     if (strEQ(name, "SO_SNDTIMEO"))
  538. #ifdef SO_SNDTIMEO
  539.         return SO_SNDTIMEO;
  540. #else
  541.         goto not_there;
  542. #endif
  543.     if (strEQ(name, "SO_TYPE"))
  544. #ifdef SO_TYPE
  545.         return SO_TYPE;
  546. #else
  547.         goto not_there;
  548. #endif
  549.     if (strEQ(name, "SO_USELOOPBACK"))
  550. #ifdef SO_USELOOPBACK
  551.         return SO_USELOOPBACK;
  552. #else
  553.         goto not_there;
  554. #endif
  555.     break;
  556.     case 'T':
  557.     break;
  558.     case 'U':
  559.     break;
  560.     case 'V':
  561.     break;
  562.     case 'W':
  563.     break;
  564.     case 'X':
  565.     break;
  566.     case 'Y':
  567.     break;
  568.     case 'Z':
  569.     break;
  570.     }
  571.     errno = EINVAL;
  572.     return 0;
  573.  
  574. not_there:
  575.     errno = ENOENT;
  576.     return 0;
  577. }
  578.  
  579. XS(XS_Socket_constant)
  580. {
  581.     dXSARGS;
  582.     if (items != 2) {
  583.     croak("Usage: Socket::constant(name,arg)");
  584.     }
  585.     {
  586.     char *    name = (char *)SvPV(ST(0),na);
  587.     int    arg = (int)SvIV(ST(1));
  588.     double    RETVAL;
  589.  
  590.     RETVAL = constant(name, arg);
  591.     ST(0) = sv_newmortal();
  592.     sv_setnv(ST(0), (double)RETVAL);
  593.     }
  594.     XSRETURN(1);
  595. }
  596.  
  597. XS(boot_Socket)
  598. {
  599.     dXSARGS;
  600.     char* file = __FILE__;
  601.  
  602.     newXS("Socket::constant", XS_Socket_constant, file);
  603.     ST(0) = &sv_yes;
  604.     XSRETURN(1);
  605. }
  606.